// 动画系统变量
// ====================
// 动画时长
$duration-fast: 150ms;
$duration-normal: 300ms;
$duration-slow: 500ms;
$duration-very-slow: 800ms;
// 动画曲线
$ease-linear: linear;
$ease-in: cubic-bezier(0.4, 0, 1, 1);
$ease-out: cubic-bezier(0, 0, 0.2, 1);
$ease-in-out: cubic-bezier(0.4, 0, 0.2, 1);
$ease-bounce: cubic-bezier(0.68, -0.55, 0.265, 1.55);
$ease-elastic: cubic-bezier(0.175, 0.885, 0.32, 1.275);
// 动画延迟
$delay-fast: 50ms;
$delay-normal: 100ms;
$delay-slow: 200ms;
// 动画距离
$distance-small: 10px;
$distance-normal: 20px;
$distance-large: 40px;
// 动画缩放
$scale-small: 0.95;
$scale-normal: 0.9;
$scale-large: 0.8;
// 基础动画工具类
// ====================

/**
 * 淡入动画
 */

.fade-in {
    animation: fadeIn $duration-normal $ease-out;
}

.fade-in-fast {
    animation: fadeIn $duration-fast $ease-out;
}

.fade-in-slow {
    animation: fadeIn $duration-slow $ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}


/**
 * 淡出动画
 */

.fade-out {
    animation: fadeOut $duration-normal $ease-in;
}

@keyframes fadeOut {
    from {
        opacity: 1;
    }
    to {
        opacity: 0;
    }
}


/**
 * 滑动动画
 */

.slide-in-up {
    animation: slideInUp $duration-normal $ease-out;
}

.slide-in-down {
    animation: slideInDown $duration-normal $ease-out;
}

.slide-in-left {
    animation: slideInLeft $duration-normal $ease-out;
}

.slide-in-right {
    animation: slideInRight $duration-normal $ease-out;
}

@keyframes slideInUp {
    from {
        opacity: 0;
        transform: translateY($distance-normal);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slideInDown {
    from {
        opacity: 0;
        transform: translateY(-$distance-normal);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slideInLeft {
    from {
        opacity: 0;
        transform: translateX($distance-normal);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateX(-$distance-normal);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}


/**
 * 缩放动画
 */

.scale-in {
    animation: scaleIn $duration-normal $ease-out;
}

.scale-out {
    animation: scaleOut $duration-normal $ease-in;
}

@keyframes scaleIn {
    from {
        opacity: 0;
        transform: scale($scale-normal);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes scaleOut {
    from {
        opacity: 1;
        transform: scale(1);
    }
    to {
        opacity: 0;
        transform: scale($scale-normal);
    }
}


/**
 * 弹性动画
 */

.bounce-in {
    animation: bounceIn $duration-slow $ease-bounce;
}

@keyframes bounceIn {
    0% {
        opacity: 0;
        transform: scale($scale-large);
    }
    50% {
        opacity: 1;
        transform: scale(1.05);
    }
    100% {
        opacity: 1;
        transform: scale(1);
    }
}


/**
 * 旋转动画
 */

.rotate-in {
    animation: rotateIn $duration-normal $ease-out;
}

@keyframes rotateIn {
    from {
        opacity: 0;
        transform: rotate(-180deg) scale($scale-normal);
    }
    to {
        opacity: 1;
        transform: rotate(0deg) scale(1);
    }
}


/**
 * 交错动画
 */

.stagger-item {
    opacity: 0;
    animation: fadeInUp $duration-normal $ease-out forwards;
}

.stagger-item:nth-child(1) {
    animation-delay: $delay-fast;
}

.stagger-item:nth-child(2) {
    animation-delay: $delay-normal;
}

.stagger-item:nth-child(3) {
    animation-delay: $delay-slow;
}

.stagger-item:nth-child(4) {
    animation-delay: 300ms;
}

.stagger-item:nth-child(5) {
    animation-delay: 400ms;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY($distance-normal);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}


/**
 * 脉冲动画
 */

.pulse {
    animation: pulse $duration-slow $ease-in-out infinite;
}

@keyframes pulse {
    0%,
    100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}


/**
 * 闪烁动画
 */

.shimmer {
    animation: shimmer $duration-slow $ease-in-out infinite;
}

@keyframes shimmer {
    0% {
        background-position: -200px 0;
    }
    100% {
        background-position: calc(200px + 100%) 0;
    }
}


/**
 * 加载动画
 */

.loading-spinner {
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}


/**
 * 页面过渡动画
 */

.page-enter-active {
    transition: all $duration-normal $ease-out;
}

.page-enter-from {
    opacity: 0;
    transform: translateY($distance-small);
}

.page-leave-active {
    transition: all $duration-fast $ease-in;
}

.page-leave-to {
    opacity: 0;
    transform: translateY(-$distance-small);
}


/**
 * 管理后台过渡动画
 */

.admin-enter-active {
    transition: all $duration-normal $ease-out;
}

.admin-enter-from {
    opacity: 0;
    transform: translateX($distance-small);
}

.admin-leave-active {
    transition: all $duration-fast $ease-in;
}

.admin-leave-to {
    opacity: 0;
    transform: translateX(-$distance-small);
}


/**
 * 模态框动画
 */

.modal-enter-active {
    transition: all $duration-normal $ease-out;
}

.modal-enter-from {
    opacity: 0;
    transform: scale($scale-normal);
}

.modal-leave-active {
    transition: all $duration-fast $ease-in;
}

.modal-leave-to {
    opacity: 0;
    transform: scale($scale-normal);
}


/**
 * 列表项动画
 */

.list-item-enter-active {
    transition: all $duration-normal $ease-out;
}

.list-item-enter-from {
    opacity: 0;
    transform: translateX(-$distance-normal);
}

.list-item-leave-active {
    transition: all $duration-fast $ease-in;
}

.list-item-leave-to {
    opacity: 0;
    transform: translateX($distance-normal);
}


/**
 * 卡片动画
 */

.card-enter {
    animation: cardPop $duration-normal $ease-out;
}

@keyframes cardPop {
    0% {
        opacity: 0;
        transform: scale($scale-normal) translateY($distance-normal);
    }
    100% {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}


/**
 * 按钮动画
 */

.btn-animated {
    transition: all $duration-fast $ease-out;
    will-change: transform, box-shadow;
}

.btn-animated:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.btn-animated:active {
    transform: translateY(0);
    transition: all $duration-fast $ease-in;
}


/**
 * 输入框动画
 */

.input-focus {
    animation: inputFocus $duration-normal $ease-out;
}

@keyframes inputFocus {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.02);
    }
    100% {
        transform: scale(1);
    }
}


/**
 * 图标动画
 */

.icon-spin {
    animation: iconSpin $duration-slow linear infinite;
}

@keyframes iconSpin {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

.icon-bounce {
    animation: iconBounce $duration-normal $ease-bounce;
}

@keyframes iconBounce {
    0%,
    20%,
    53%,
    80%,
    100% {
        transform: translateY(0);
    }
    40%,
    43% {
        transform: translateY(-8px);
    }
    70% {
        transform: translateY(-4px);
    }
    90% {
        transform: translateY(-2px);
    }
}


/**
 * 响应式动画
 */

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}


/**
 * 动画工具类
 */

.animate-none {
    animation: none;
}

.animate-pause {
    animation-play-state: paused;
}

.animate-play {
    animation-play-state: running;
}

.animate-fill-both {
    animation-fill-mode: both;
}

.animate-fill-forwards {
    animation-fill-mode: forwards;
}

.animate-fill-backwards {
    animation-fill-mode: backwards;
}

.micro-interaction {
    position: relative;
    overflow: hidden;
    transition: all $duration-fast $ease-out;
    will-change: transform, box-shadow, opacity;
    // 按钮样式
    &.micro-button {
        cursor: pointer;
        -webkit-user-select: none;
        user-select: none;
        &:not(.is-disabled) {
            &:hover {
                transform: translateY(-2px);
                box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
            }
            &:active {
                transform: translateY(0);
                transition: all $duration-fast $ease-in;
            }
        }
    }
    // 输入框样式
    &.micro-input {
        &:not(.is-disabled) {
            &.is-focused {
                animation: inputFocus $duration-normal $ease-out;
            }
        }
    }
    // 卡片样式
    &.micro-card {
        cursor: pointer;
        &:not(.is-disabled) {
            &:hover {
                transform: translateY(-4px);
                box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
            }
            &:active {
                transform: translateY(-2px);
            }
        }
    }
    // 链接样式
    &.micro-link {
        cursor: pointer;
        &:not(.is-disabled) {
            &:hover {
                transform: scale(1.05);
            }
            &:active {
                transform: scale(0.95);
            }
        }
    }
    // 图标样式
    &.micro-icon {
        cursor: pointer;
        &:not(.is-disabled) {
            &:hover {
                transform: scale(1.2);
            }
            &:active {
                transform: scale(0.9);
            }
        }
    }
    // 禁用状态
    &.is-disabled {
        cursor: not-allowed;
        opacity: 0.6;
        &:hover,
        &:active,
        &:focus {
            transform: none;
            box-shadow: none;
        }
    }
}

// 涟漪动画
@keyframes ripple {
    0% {
        transform: scale(0);
        opacity: 1;
    }
    100% {
        transform: scale(4);
        opacity: 0;
    }
}

// 输入框焦点动画
@keyframes inputFocus {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.02);
    }
    100% {
        transform: scale(1);
    }
}

// 响应式动画
@media (prefers-reduced-motion: reduce) {
    .micro-interaction {
        transition: none !important;
        animation: none !important;
        &:hover,
        &:active,
        &:focus {
            transform: none !important;
            box-shadow: none !important;
        }
    }
    .ripple-effect {
        display: none !important;
    }
}